package ru.infosystem.client.model;

import java.util.ArrayList;
import javax.swing.table.AbstractTableModel;
import ru.infosystem.client.data.Student;

/**
 *
 * @author akoshi
 */
public class StudentTableModel extends AbstractTableModel {

    private final int columnsNumber = 3;
    private final String[] columnsNames = {
        "FIO", "Income", "Group"
    };
    private ArrayList<String[]> resultSets;

    public StudentTableModel(Student[] students) {

        resultSets = new ArrayList<String[]>();

        try {

            for (Student st : students) {

                String[] row = {
                    st.getSurname() + " " + st.getName() + " " + st.getPatronymic(),
                    st.getIncome().toString(),
                    Integer.toString(st.getGroupNumber())
                };

                resultSets.add(row);
            }

        } catch (Exception e) {
            System.out.println("Exception in StudentTableModel");
        }
    }

    @Override
    public Object getValueAt(int rowindex, int columnindex) {

        String[] row = resultSets.get(rowindex);

        return row[columnindex];

    }

    @Override
    public int getRowCount() {
        return resultSets.size();
    }

    @Override
    public int getColumnCount() {
        return columnsNumber;
    }

    @Override
    public String getColumnName(int param) {

        return columnsNames[param];
    }
}
